package cn.evilcoder;

import org.junit.*;

import java.io.Closeable;
import java.io.IOException;

/**
 * User: evilcoder
 * Date: 2015/8/23
 * Time: 11:38
 */
public class FixturesTest {

  private ManagedResource myManagedResource;
  private static ExpensiveManagedResource myExpensiveManagedResource;

  //一些昂贵的数据准备，比如数据库链接，文件读取
  static class ExpensiveManagedResource implements Closeable {
    @Override
    public void close() throws IOException {}
  }
  static class ManagedResource implements Closeable {
    @Override
    public void close() throws IOException {}
  }
  @BeforeClass
  public static void setUpClass() {
    System.out.println("@BeforeClass setUpClass");
    myExpensiveManagedResource = new ExpensiveManagedResource();
  }

  @AfterClass
  public static void tearDownClass() throws IOException {
    System.out.println("@AfterClass tearDownClass");
    myExpensiveManagedResource.close();
    myExpensiveManagedResource = null;
  }
  @Before
  public void setUp() {
    System.out.println("@Before setUp");
    this.myManagedResource = new ManagedResource();
  }

  @After
  public void tearDown() throws IOException {
    System.out.println("@After tearDown");
    this.myManagedResource.close();
    this.myManagedResource = null;
  }

  @Test
  public void test1() {
    System.out.println("@Test test1()");
  }

  @Test
  public void test2() {
    System.out.println("@Test test2()");
  }
}
